import abc, random

class LocalStateManager(object):

	metaclass = abc.ABCMeta
	roundValue = 10	#need to find correct value for round search
	
	def __init__(self):
		LocalStateManager(self, None)

	def __init__(self, k):
		self.currentState = None
		self.currentMode = k-1
	
	'''def __subclasshook__(sub ,C):
		return NotImplemented'''
	
	#generate initial state
	@abc.abstractmethod
	def generateInitState(self):
		variables = [-1]*self.k-1
		random.seed() #init a random generator
		x = random.randint(0, self.k-1) #choose a random variable
		d = random.randint(0, self.k-1)		#choose a random value from the domain values
		variables[x] = d
		self.currentState = variables
		return  self.currentState
	
	#modify the state - method can be random or intelligent
	@abc.abstractmethod
	def modifyState(self, method): pass
	
	#generate successor of the current state
	@abc.abstractmethod
	def generateSuccessors(self):
		global roundValue
		successors = []
		copy_state = list(self.currentState)
		for i in range(roundValue):		#generate 5 successors random states
			indexVar = random.randint(0, self.currentState.count(-1)-1) #counting vars not assigned (unassigned column)
			while True:
				valVar = random.randint(0, len(self.currentState)) # selecting a non assigned row
				if(valVar not in self.currentState):
					break
			for v in copy_state:
				if indexVar == 0:
					v = valVar
				if v == -1:
					indexVar-= 1
			if self.evalutateState(copy_state):
				successors += [copy_state]
		return successors
	
	#evalutate the state (checking costraints violations)
	@abc.abstractmethod
	def evalutateState(self, state): pass
	
	#display the state (for showing final solution)
	@abc.abstractmethod
	def displayState(self):
		print self.currentState
	